package com.anhry.www.safety.manage.oa.struts.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.anhry.www.safety.manage.oa.bean.TbCorpMsg;
import com.anhry.www.safety.manage.oa.struts.base.OABaseAction;
import com.anhry.www.safety.util.Loggers;
import com.anhry.www.safety.util.Page;

/**
 * @date:2012-10-31
 * @remark:公告通知和在线帮助
 * @author:dongbin
 */
@Controller
@Scope("prototype")
@SuppressWarnings("unchecked")
public class MsgAction extends OABaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private List objList;
	private String cType;
	private TbCorpMsg msg;
	private List fjList;
	private String id;
	
	public String list(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		try {
			String orderHql = " order by t.msgDate desc";//排序hql语句
			if(null==this.cType || "".equals(this.cType)){
				return ERROR;
			}
			StringBuilder hql = new StringBuilder(" where 1=1 and t.msgType="+this.cType);
			List objSize = this.utilService.getObjecList("TbCorpMsg", hql.toString(), orderHql,0, 0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setObjList(this.utilService.getObjecList("TbCorpMsg", hql.toString(), orderHql,page.getStartRow(),page.getSize()));
			this.setResult("msg_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("oa: MsgAction:list() 异常："+e.getMessage());
		}
		return ERROR;
	}
	
	public String show(){
		try {
			if(null!=this.id && this.id.length()>0){
				TbCorpMsg msg = (TbCorpMsg)this.utilService.getObjectById(TbCorpMsg.class, Long.parseLong(id));
				if(null!=msg){
					this.setMsg(msg);
					this.setFjList((List)this.utilService.getHqlQuery("from TbCorpMsgFj t where 1=1 and t.msgId="+id+" order by t.id"));
					this.setResult("msg_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("oa: MsgAction:show() 异常："+e.getMessage());
		}
		return ERROR;
	}

	public String getCType() {
		return cType;
	}

	public void setCType(String type) {
		cType = type;
	}

	public List getObjList() {
		return objList;
	}

	public void setObjList(List objList) {
		this.objList = objList;
	}

	public List getFjList() {
		return fjList;
	}

	public void setFjList(List fjList) {
		this.fjList = fjList;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public TbCorpMsg getMsg() {
		return msg;
	}

	public void setMsg(TbCorpMsg msg) {
		this.msg = msg;
	}

}
